using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using viBook.Models;

namespace viBook.Controllers
{
    public class ContentTagsController : BaseController
    {
        #region Constructors and Repository vars

        private readonly IContentTagRepository contenttagRepository;

        // If you are using Dependency Injection, you can delete the following constructor
        public ContentTagsController()
            : this(new ContentTagRepository())
        {
        }

        public ContentTagsController(IContentTagRepository contenttagRepository)
        {
            this.contenttagRepository = contenttagRepository;
        }

        #endregion

        public ViewResult Index()
        {
            return View(contenttagRepository.All);
        }

        public ViewResult Details(int id)
        {
            return View(contenttagRepository.Find(id));
        }

        public ActionResult Edit(ContentTag contenttag)
        {
            if (ModelState.IsValid)
            {
                contenttagRepository.InsertOrUpdate(contenttag);
                contenttagRepository.Save();
                return RedirectToAction("Index");
            }
            else
            {
                return View();
            }
        }

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            contenttagRepository.Delete(id);
            contenttagRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

